#include <thread>
#include <iostream>
#include <vector>
#include <functional>
using namespace std;

//在一个循环中递增一个通过引用参数传入的整数值
void func(int& counter)
{
    for (int i = 0;i < 100000;++i){
        ++counter;
    }
}

int main()
{
    int counter = 0;
    vector<thread> threads;
    for(int i = 0;i<10;++i){
        threads.push_back(thread{func,ref(counter)});
    }
    for(auto& t :threads){
            t.join();
    }
    cout << "Result = " << counter << endl;
    return 0;
}